package com.oracleoaec.util;

import java.util.Scanner;

import com.oracleoaec.myexception.MyException;

public class InputException {
	//讲inputException封装成一个可以循环输入的工具包
		public static Integer input(String str) {
			System.out.println(str);//提示信息
			Integer num=null;
			while((num=inputException())==null){
				System.out.println(str);
			}
			return num;
		}
		//解决输入异常
		@SuppressWarnings("resource")
		public static Integer inputException() {
			Integer num=null;
			Scanner scanner1=null;
			try {
				scanner1=new Scanner(System.in);
				num=scanner1.nextInt();
			} catch (Exception e) {
				try {
					//使用自定异常，输入不匹配异常并捕获
					throw new MyException("☛输入非法字符！");
				} catch (MyException e1) {
					//e.printStackTrace();
					System.out.println(e1.getMessage());
				}
			}
			return num;
		}
}
